﻿// UnlockAchievementForm.cs
using MaterialSkin;
using MaterialSkin.Controls;
using System;
using System.Windows.Forms;
using TomatoClock.Models;
using TomatoClock.Services;

namespace TomatoClock.Views
{
    public partial class UnlockAchievementDialog : MaterialForm
    {
        private readonly MaterialSkinManager materialSkinManager;
        private readonly Achievement achievement;
        // 添加一个属性用于获取成就名字
        public string AchievementName => achievement.Name;

        // 添加一个事件，当点击 OK 按钮时触发
        public event EventHandler<EventArgs> OKClicked;

        public UnlockAchievementDialog(Achievement achievement)
        {
            InitializeComponent();
            this.achievement = achievement;
            materialSkinManager = MaterialSkinManager.Instance;
            materialSkinManager.AddFormToManage(this);
            materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT;
            materialSkinManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE);

            // 显示成就信息
            AchievementTextBox.Text = "恭喜你解锁了成就："+achievement.Name;
            string path = Path.Combine(Application.StartupPath, "Resources/Achievements", achievement.ImagePath);
            AchievementPictureBox.SizeMode=PictureBoxSizeMode.StretchImage;
            AchievementPictureBox.Image = LoadImage(path);
        }

        public UnlockAchievementDialog()
        {
            InitializeComponent();
            materialSkinManager = MaterialSkinManager.Instance;
            materialSkinManager.AddFormToManage(this);
            materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT;
            materialSkinManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE);

            // 显示成就信息
            AchievementTextBox.Text = "很遗憾，你当前没有成就";
            OKButton.Text = "好吧";
            string path = Path.Combine(Application.StartupPath, "Resources/Achievements", "Lock.png");//锁图片
            AchievementPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
            AchievementPictureBox.Image = LoadImage(path);
        }

        private Image LoadImage(string imagePath)
        {
            try
            {
                return Image.FromFile(imagePath);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error loading image {imagePath}: {ex.Message}");
                return null;
            }
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            // 关闭窗体
            this.Close();
        }
    }
}
